package com.zg.common.core.dao.scf.mapper;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zg.common.core.dao.scf.entity.AccAccount;
import com.zg.common.core.req.PageReq;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>Description: </p>
 *
 * @author zhanfeng.liang
 * @since 2025/5/21 20:49
 */
@Mapper
public interface AccAccountMapper extends BaseMapper<AccAccount> {

    @Select("<script>" +
            "SELECT account.*, company.name as companyName FROM acc_account account " +
            "LEFT JOIN scf_company company ON company.id = account.company_id " +
            "<where>" +
            "  company.is_del = 0 and account.is_del=0" +
            "   <if test=\"pageReq.companyName != null and pageReq.companyName != ''\"> AND company.name LIKE '%' || #{pageReq.companyName} || '%'</if>" +
            "   <if test=\"pageReq.beginTime != null \">   AND account.create_time &gt;= #{pageReq.beginTime}</if>" +
            "   <if test=\"pageReq.endTime != null \"> AND account.create_time &lt;= #{pageReq.endTime} </if>" +
            "  <if test=\"ew != null and ew.sqlSegment != ''\"> AND ${ew.sqlSegment}</if>" +
            "</where>" +
            "</script>")
    Page<AccAccount> page(Page<AccAccount> page,
                          @Param(Constants.WRAPPER) LambdaQueryWrapper<AccAccount> wrapper, @Param("pageReq") PageReq pageReq);
}
